<template>
	<view class="container">
		<view class="top">
			<input 
				type="text" 
				placeholder="请输入待办事项" 
				v-model="value" 
				class="input-box"
			/>
			<view class="createButton" @click="handleClick">添加</view>
		</view>

		<view class="bottom">
			<view class="title">📌 待办事项</view>
			<view v-for="(item, index) in showList" :key="item.id" v-if="item.status === 'todo'">
				<view class="todo-item doing">
					<checkbox @click="doingHandle(item.id)" />
					<text>{{ item.value }}</text>
					<view class="delete-btn" @click.stop="deleteItem(item.id)">🗑️</view>
				</view>
			</view>

			<view class="title">✅ 已办事项</view>
			<view v-for="(item, index) in showList" :key="item.id" v-if="item.status === 'finished'">
				<view class="todo-item done">
					<checkbox @click="doneHandle(item.id)" checked="true" />
					<text class="line-through">{{ item.value }}</text>
					<view class="delete-btn" @click.stop="deleteItem(item.id)">🗑️</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showList: [],
				value: ''
			}
		},
		methods: {
			handleClick() {
				if (this.value.trim() === '') return;
				this.showList.push({
					value: this.value,
					status: 'todo',
					id: new Date().getTime()
				});
				this.value = '';
			},
			doingHandle(id) {
				const item = this.showList.find(item => item.id === id);
				if (item) item.status = 'finished';
			},
			doneHandle(id) {
				const item = this.showList.find(item => item.id === id);
				if (item) item.status = 'todo';
			},
			deleteItem(id) {
				this.showList = this.showList.filter(item => item.id !== id);
			}
		}
	}
</script>

<style>
	.container {
		padding: 20rpx;
		background-color: #f9f9f9;
		min-height: 100vh;
	}

	.top {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 0;
		border-bottom: 1px solid #eee;
	}

	.input-box {
		flex: 1;
		height: 80rpx;
		padding: 0 20rpx;
		margin-left: 20rpx;
		border-radius: 40rpx;
		background-color: #fff;
		border: 1px solid #ddd;
		font-size: 28rpx;
	}

	.createButton {
		width: 140rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: linear-gradient(to right, #667eea, #764ba2);
		color: white;
		font-weight: bold;
		border-radius: 40rpx;
		margin-right: 20rpx;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.bottom {
		margin-top: 30rpx;
	}

	.title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-top: 40rpx;
	}

	.todo-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ffffff;
		padding: 20rpx;
		border-radius: 16rpx;
		margin-top: 20rpx;
		box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
		transition: background-color 0.3s ease;
	}

	.doing {
		border-left: 6rpx solid #aa0000;
	}

	.done {
		border-left: 6rpx solid #4caf50;
	}

	.line-through {
		text-decoration: line-through;
		color: #999;
	}

	.delete-btn {
		color: #999;
		font-size: 36rpx;
		padding: 0 20rpx;
		opacity: 0.7;
		transition: opacity 0.2s ease;
	}

	.delete-btn:hover {
		opacity: 1;
		color: red;
	}
</style>